﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Boco.Digg.Utilities;
namespace Boco.Digg.Service
{
	public class Arguments : IArguments
	{
		private Dictionary<string, string> _arguments = new Dictionary<string, string>();

		public IArguments Count(int count)
		{
			if (_arguments.ContainsKey("count") == false)
				_arguments.Add("count", count.ToString());
			else
				_arguments["count"] = count.ToString();

			return this;
		}

		public IArguments MinDate(DateTime minDate)
		{
			int epochTime = minDate.ToUnixEpoch();
			if (_arguments.ContainsKey("minDate") == false)
				_arguments.Add("minDate", epochTime.ToString());
			else
				_arguments["minDate"] = epochTime.ToString();

			return this;
		}

		public IArguments MaxDate(DateTime maxDate)
		{
			int epochTime = maxDate.ToUnixEpoch();
			if (_arguments.ContainsKey("maxDate") == false)
				_arguments.Add("maxDate", epochTime.ToString());
			else
				_arguments["maxDate"] = epochTime.ToString();

			return this;
		}

		public override string ToString()
		{
			StringBuilder builder = new StringBuilder();

			builder.Append("?");
			foreach (KeyValuePair<string, string> pair in _arguments)
			{
				builder.Append(string.Format("{0}={1}", pair.Key, pair.Value));
				builder.Append("&");
			}
			builder.Remove(builder.Length - 1, 1);

			return builder.ToString();
		}
	}
}
